using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIManager : Singleton_Base<UIManager>
{
    public override bool isDontDestroy => false;
    [SerializeField]
    private Image blackMask_Image;
    private IEnumerator blackMaskIE;

    public ObjectGroup<string, GameObject> panel_Group;

    // Update is called once per frame
    void Update()
    {

    }

    public T GetPanel<T>(string name) where T:MonoBehaviour
    {
        GameObject target = panel_Group[name];
        if (target != null)
        {
            return target.GetComponent<T>();
        }
        return null;
    }
    public void HideAllPanel()
    {
        for(int i=0;i< panel_Group.Count; i++)
        {
            panel_Group[i].gameObject.SetActive(false);
        }
    }
    public void SwtichMaskPerformance(bool isSwitch, float time = 0,System.Action finishAction=null)
    {
        blackMask_Image.raycastTarget = isSwitch;
        float initAlpha = blackMask_Image.color.a;
        float targetAlpha = isSwitch ? 1 : 0;
        IEPool_Manager.instance.KeepTimeToDo(ref blackMaskIE, time, null, (_time) =>
        {
            blackMask_Image.color = new Color(blackMask_Image.color.r, blackMask_Image.color.g, blackMask_Image.color.b, Mathf.Lerp(initAlpha, targetAlpha, 1 - _time / time));
            return true;
        }, () =>
        {
            blackMask_Image.color = new Color(blackMask_Image.color.r, blackMask_Image.color.g, blackMask_Image.color.b, targetAlpha);
            finishAction?.Invoke();
            if (!isSwitch)
            {
                blackMask_Image.raycastTarget = false;
            }
        });
    }
}
